#include "qsearchterms.h"

QSearchTerms::QSearchTerms(QString field,QString text,QString mean,quint8 value,QWidget *parent , Qt::WFlags flags )
: QWidget(parent,flags)
{
	ui.setupUi(this);
	m_field = field;
	m_check = mean;
	m_text = text;
	m_normalizedField = field;
	m_normalizedText = text;
	m_normalizedField.remove("\"").remove(EXP_UNKNOWN);
	m_normalizedText.remove("\"").remove(EXP_UNKNOWN);
	ui.value->setText(m_normalizedText);
	ui.weight->setValue(value);
	ui.terms->setText(m_normalizedField);
	connect(ui.value,SIGNAL(textChanged(const QString &)),this,SLOT(textEdited()));
}

QSearchTerms::~QSearchTerms()
{
}



QStringList QSearchTerms::terms() const
{
	QStringList terms;
	if(!m_normalizedText.isEmpty())
		terms << m_field << m_normalizedText << m_check << QString("%1").arg(ui.weight-> value());
	return terms;
}


void QSearchTerms::textEdited()
{
	m_text = "\"" + ui.value->text() + "\""; 
	m_normalizedText = ui.value->text();
}

void QSearchTerms::set(QString field,QString text,QString mean,quint8 value)
{
	m_field = field;
	m_check = mean;
	m_text = text;
	m_normalizedField = field;
	m_normalizedText = text;	
	m_normalizedField.remove("\"").remove(EXP_UNKNOWN);
	m_normalizedText.remove("\"").remove(EXP_UNKNOWN);
	ui.value->setText(m_normalizedText);
	ui.weight->setValue(value);
	ui.terms->setText(m_normalizedField);
}